﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;

namespace tsgl
{
    class returnOrRenewClass
    {
        public static DataTable getLoanInfoByBarcode(string barcode)
        {
            string str = "select * from loanView where 图书条码="+ barcode +" order by 借阅编号";
            return bookDbClass.ExecuteDataTable(str);
        }

        public static Boolean loanRenew(int maxDay, string borrowerId, string bookBarcode)
        {
            try
            {
                string str = "update 借阅信息 set 借出日期=@a,应还日期=@b,续借次数=续借次数+1 where 借阅者编号=@c and 图书条码=@d";
                bookDbClass.ExecuteNonQurey(str, new SqlParameter("a", DateTime.Today.ToShortDateString()), new SqlParameter("b", DateTime.Today.AddDays(maxDay).Date.ToShortDateString()), new SqlParameter("c", borrowerId), new SqlParameter("d", bookBarcode));
                return true;
            }
            catch (Exception)
            {
                return false;
            }

        }

        public static Boolean loanDelete(string borrowerId, string bookCode)
        {
            try
            {
                string str = "delete from 借阅信息 where 借阅者编号 =@a and 图书条码=@b";
                bookDbClass.ExecuteNonQurey(str, new SqlParameter("a", borrowerId), new SqlParameter("b", bookCode));
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        //public void bookNowNumAdd(string bibliothecaId)
        //{
        //    string str="update 书目信息 set 现存数量=现存数量+1 where 书目编号=@a";
        //    bookDbClass.ExecuteNonQurey(str,new SqlParameter("a",bibliothecaId));
        //}
    }
}
